//
//  MyViewController.m
//  yonghu
//
//  Created by 浪尖渝力 on 2018/1/15.
//  Copyright © 2018年 com.DJS. All rights reserved.
//

#import "MyViewController.h"
#import "MyView.h"

@interface MyViewController ()
@property(nonatomic,strong)MyView *aView;
@end

@implementation MyViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self wr_setNavBarBackgroundAlpha:0];
    
    [self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
    [self.navigationController.navigationBar setShadowImage:[UIImage new]];
    
    _aView=[MyView new];
    [self.view addSubview:_aView];
    [_aView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.mas_equalTo(0);
    }];
    _aView.viewController=self;
    [_aView creatView];
    
    UIButton *btn=[UIButton new];
    [self.view addSubview:btn];
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-10);
        make.bottom.mas_equalTo(-70);
        make.width.height.mas_equalTo(50);
    }];
    [btn setImage:[UIImage imageNamed:@"客服"] forState:0];
    [btn addTarget:self action:@selector(setviewinfo) forControlEvents:UIControlEventTouchUpInside];
}
-(void)setviewinfo{
    self.navigationItem.rightBarButtonItem.enabled=NO;
    [ZQTools AFNPostDataUrl:@"api/index/get_service_phone" Dict:nil andTableView:nil andViewController:self andSuccessBlock:^(id responseObject) {
        self.navigationItem.rightBarButtonItem.enabled=YES;
        NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"tel:%@",responseObject];
        UIWebView * callWebview = [[UIWebView alloc] init];
        [callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];
        [self.view addSubview:callWebview];
        
    } anderrorBlock:nil];
}
-(void)viewWillAppear:(BOOL)animated{
    [self loginView];
}

-(void)loginView{
    _aView.userDic=nil;
    NSDictionary *userDic = [NSKeyedUnarchiver unarchiveObjectWithFile:_userModelFile];
    if (userDic==nil) {
        [ZQTools cleanViewSubviews:_aView];
        [_aView creatView];
        return;
    }
    NSString *token=[userDic objectForKey:@"token"];
    NSNumber *waiter_id1=[userDic objectForKey:@"user_id"];
    NSString *user_id=[NSString stringWithFormat:@"%@",waiter_id1];
    
    NSDictionary *dic=[NSDictionary dictionaryWithObjectsAndKeys:@"0",@"user_role",token,@"token",user_id,@"user_id", nil];
    [ZQTools AFNPostDataUrl:@"user/user/user_info" Dict:dic andTableView:nil andViewController:self andSuccessBlock:^(id responseObject) {
        [ZQTools cleanViewSubviews:_aView];
        _aView.userDic=responseObject;
        [_aView creatView];
    } anderrorBlock:nil];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
